<?php
if (!defined('ROOT')) exit('Can\'t Access !');

/**
 * 基础控制器类
 * Class controller_class
 */
class controller_class
{
    public function __construct($module, $action)
    {
        $this->modules($module, $action);
    }

    public function modules($module, $action)
    {
        $extfile = 'mod_'.$module;

        $modulepath = PATH.'modules/'.$extfile.'.php';
        $modulepath = str_replace('\\', '/', $modulepath);
        if(!file_exists($modulepath)) error("What are you doing?");
        require($modulepath);
        if(!class_exists($extfile)) error("Module '$module' class not found");
        $this->module = new $extfile($module,$action);
        if(!method_exists($extfile,$action) === true) error("Module({$module})'s Action '$action' not found");
        if($action == 'template') error("Module({$module})'s Action '$action' is'not effective");
        if(@$this->module->$action()) error("Module({$module})'s Action '$action' is'not effective");
    }

    public function display()
    {
        $this->module->template();
    }
}
?>